<?php

require(INSTALLER_PATH.'/config.php');

# seed the random generator
srand ((double) microtime() * 1000000);
$rmax=getrandmax();

$versions = new VersionSet();

$version = new Version($short_version, $long_version);

$version->addSeparator('Informacion General');
$version->collectOption('Estado', 'Estado Venezolano', array('Amazonas', 'Anzoategui', 'Apure', 'Aragua', 'Barinas', 'Bolivar', 'Carabobo', 'Cojedes', 'Delta Amacuro', 'Distrito Capital', 'Falcon', 'Guarico', 'Lara', 'Merida', 'Miranda', 'Monagas', 'Nueva Esparta', 'Portuguesa', 'Sucre', 'Tachira', 'Trujillo', 'Vargas', 'Yaracuy', 'Zulia'), array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'), '10');
$version->collectText('db_centername', 'Nombre del Centro de Salud', '');
$version->addSeparator('Informacion de la Base de Datos');
$version->collectOption('db_type', 'Tipo de Servidor', array('MySQL'), array('mysql'), 'mysql');
$version->collectText('db_user', 'Nombre de Usuario', 'root');
$version->collectText('cypherPass', 'Contraseña para cifrado de las contraseñas de usuarios','abcdefghijuklmno0123456789012345');
$version->collectPassword('db_password', 'Contrasena', '');
$version->collectText('db_server', 'Direccion del Servidor', 'localhost');
$version->collectText('db_database', 'Nombre de la Base de Datos', 'care2x');
$version->collectOption('Script', 'Ejecutar Scripts Instalacion SQL', array('Si','No'), array('Si','No'), 'No');
$version->addSeparator('Usuario Administrador del Sistema');
$version->collectText('admin_user', 'Nombre de Usuario', 'admin');
$version->collectPassword('admin_password', 'Contrasena', '');
$version->collectPassword('admin_confirm', 'Confirmacion de Contrasena', '');
$version->addSeparator('Protocolo de Red y Dominio');
$version->collectOption('transfer_protocol', 'Protocolo de Transferencia', array('http', 'https'), array('http', 'https'), 'http');
$version->collectText('care2x_address', 'Host de SINAPSIS', 'localhost');
$version->addSeparator('Llaves de Encriptacion');
$version->collectText('1st_key', '1ra llave', (rand(1,$rmax).rand(1,$rmax))*rand(1,$rmax));
$version->collectText('2nd_key', '2da llave', (rand(1,$rmax).rand(1,$rmax))*rand(1,$rmax));
$version->collectText('3rd_key', '3ra llave', (rand(1,$rmax).rand(1,$rmax))*rand(1,$rmax));
$version->addSeparator('');
$version->addTest('PHPVersionOver', array('5.0.0'));
//cambio de version de 5.0.0 a 5.3.1
$version->addTest('PHPVersionUnder', array('5.3.1'));
//$version->addTest('PHPMemory', array('8M'));
//$version->addTest('PHPMagicQuotes', array('Off'));
//$version->addTest('PHPRegisterGlobals', array('Off'));
$version->addTest('PHPDBExtension', array('type_field' => 'db_type'));
$version->addTest('PHPExtension', array('calendar', 'gd'));
$version->addTest('DBVersionOver', array(
    'username_field' => 'db_user',
    'password_field' => 'db_password',
    'server_field' => 'db_server',
    'type_field' => 'db_type',
    'version' => array('mysql' => '3.23.0', 'postgres7' => '7.4.0')));
$version->addTest('AdminPasswordConfirmed', array(
    'password_field' => 'admin_password',
    'confirm_field' => 'admin_confirm'));
$version->addTest('WritableLocation', array(APP_PATH.'/cache'));
$version->addTest('WritableLocation', array(APP_PATH.'/cache/barcodes'));
$version->addTest('WritableLocation', array(APP_PATH.'/counter'));
$version->addTest('WritableLocation', array(APP_PATH.'/counter/hitcount.txt'));
$version->addTest('WritableLocation', array(APP_PATH.'/fotos'));
$version->addTest('WritableLocation', array(APP_PATH.'/fotos/encounter'));
$version->addTest('WritableLocation', array(APP_PATH.'/fotos/registration'));
//$version->addTest('WritableLocation', array(APP_PATH.'/fotos/news'));
$version->addTest('WritableLocation', array(APP_PATH.'/logs'));
$version->addTest('WritableLocation', array(APP_PATH.'/logs/access'));
$version->addTest('WritableLocation', array(APP_PATH.'/logs/access/'.date('Y')));
$version->addTest('WritableLocation', array(APP_PATH.'/logs/access_fail'));
$version->addTest('WritableLocation', array(APP_PATH.'/logs/access_fail/'.date('Y')));
//$version->addTest('WritableLocation', array(APP_PATH.'/pharma'));
//$version->addTest('WritableLocation', array(APP_PATH.'/pharma/img'));
//$version->addTest('WritableLocation', array(APP_PATH.'/med_depot'));
//$version->addTest('WritableLocation', array(APP_PATH.'/med_depot/img'));
$version->addTest('WritableLocation', array(APP_PATH.'/radiology'));
$version->addTest('WritableLocation', array(APP_PATH.'/radiology/dicom_img'));
$version->addTest('WritableLocation', array(APP_PATH.'/gui'));
$version->addTest('WritableLocation', array(APP_PATH.'/gui/img'));
$version->addTest('WritableLocation', array(APP_PATH.'/gui/img/logos_dept'));
$version->addTest('WritableLocation', array(APP_PATH.'/gui/smarty_template/templates_c'));
$version->addTest('WritableLocation', array(APP_PATH.'/include'));
$version->addTest('WritableLocation', array(APP_PATH.'/include/inc_init_main.php'));
$version->addTest('WritableLocation', array(APP_PATH.'/installer'));
$version->addTest('WritableLocation', array(APP_PATH.'/installer/install.php'));

$version->addAction('AcceptText', 'Acuerdo de Licencia', array(dirname(__FILE__).'/LICENSE'));
$version->addAction('SQLFile', 'Instalar Esquema de la Base de Datos, Esquema de Base de Datos Para Historia Clinica y Modulo de Interconsulta', array(
	'centername_field' => 'db_centername',
    'username_field' => 'db_user',
    'password_field' => 'db_password',
    'server_field' => 'db_server',
    'type_field' => 'db_type',
    'db_field' => 'db_database',
    'estado_Field' => 'Estado',
    'script_Field' => 'Script',
    'files' => array(	dirname(__FILE__).'/db/sql/%type%_dump.sql',
			dirname(__FILE__).'/db/sql/upgrade-care2x-to-sinapsis.sql',
			dirname(__FILE__).'/db/sql/care_modulo_interconsulta.sql',
			dirname(__FILE__).'/db/sql/care_modulo_interconsulta_data.sql',
			dirname(__FILE__).'/db/sql/care_history_module.sql',
			dirname(__FILE__).'/db/sql/care_history_module_data.sql',
			dirname(__FILE__).'/db/sql/care_centro_salud.sql',
			dirname(__FILE__).'/db/sql/care_sincronizacion-v1.sql',
                        dirname(__FILE__).'/db/sql/care_modulo_usuarios.sql',
                        dirname(__FILE__).'/db/sql/rbac_role-v1.sql',
                        dirname(__FILE__).'/db/sql/rbac_action-v1.sql',
                        dirname(__FILE__).'/db/sql/rbac_asignation-v1.sql',
                        dirname(__FILE__).'/db/sql/rbac_permission-v1.sql',
			dirname(__FILE__).'/db/sql/rbac_resource-v1.sql')));


$version->addAction('ReplaceString', 'Guardando la Configuracion del Sistema', array(
	'message' => "Configuracion Guardada",
	'files' => array(
		dirname(__FILE__).'/inc_init_main.php.dist' => '/var/SINAPSIS_CONFIG.php'),
	'fields' => array(
		'INSTALL_DB_CENTERNAME' => 'db_centername',
		'INSTALL_DB_USERNAME' => 'db_user',
		'INSTALL_DB_PASSWORD' => 'db_password', 
		'INSTALL_DB_DATABASE' => 'db_database', 
		'INSTALL_DB_SERVER' => 'db_server',
        'INSTALL_DB_TYPE' => 'db_type',
        'INSTALL_ADDRESS' => 'care2x_address',
        'INSTALL_PROTOCOL' => 'transfer_protocol',
        'INSTALL_KEY_1' => '1st_key',
        'INSTALL_KEY_2' => '2nd_key',
        'INSTALL_KEY_3' => '3rd_key',
        'CYPHER_PASS' => 'cypherPass')
	));

$version->addAction('CreateAdmin', 'Creando Usuario Administrador', array(
    'centername_field' => 'db_centername',
    'username_field' => 'db_user',
    'password_field' => 'db_password',
    'server_field' => 'db_server',
    'type_field' => 'db_type',
    'db_field' => 'db_database',
    'adminuser_field' => 'admin_user',
    'script_Field' => 'Script',
    'Cypher' => 'cypherPass',
    'adminpass_field' => 'admin_password'));

/*$version->addAction('ReplaceString', 'Guardando la Configuracion del Sistema Para Interconsulta', array(
	'message' => "Configuracion Guardada Para Interconsulta",
	'files' => array(
		dirname(__FILE__).'/ic_connection.php.dist' => APP_PATH.'/modules/interconsulta/include/connection.php'),
	'fields' => array(
		'INSTALL_DB_CENTERNAME' => 'db_centername',
		'INSTALL_DB_USERNAME' => 'db_user',
		'INSTALL_DB_PASSWORD' => 'db_password', 
		'INSTALL_DB_DATABASE' => 'db_database', 
		'INSTALL_DB_SERVER' => 'db_server',
                'INSTALL_DB_TYPE' => 'db_type'
                )
	));*/

/*$version->addAction('ReplaceString', 'Guardando la Configuracion del Sistema Para Historia Clinica', array(
	'message' => "Configuracion Guardada Para Historia Clinica",
	'files' => array(
		dirname(__FILE__).'/ic_connection.php.dist' => APP_PATH.'/modules/historia_clinica/include/connection.php'),
	'fields' => array(
		'INSTALL_DB_CENTERNAME' => 'db_centername',
		'INSTALL_DB_USERNAME' => 'db_user',
		'INSTALL_DB_PASSWORD' => 'db_password', 
		'INSTALL_DB_DATABASE' => 'db_database', 
		'INSTALL_DB_SERVER' => 'db_server',
                'INSTALL_DB_TYPE' => 'db_type'
                )
	));*/

$version->addAction('CSVOptions', 'Instalar Tablas Opcionales en la Base de Datos', array(
	'centername_field' => 'db_centername',
    'username_field' => 'db_user',
    'password_field' => 'db_password',
    'server_field' => 'db_server',
    'type_field' => 'db_type',
    'db_field' => 'db_database',
    'files' => array(
        dirname(__FILE__).'/db/icd10',
        dirname(__FILE__).'/db/ops301')));

$version->addFinalAction('RenameFile', 'Renombrando Archivos Criticos de Instalacion', array(
    'message' => "Archivos Criticos de Instalacion Renombrados",
    'files' => array(
        APP_PATH.'/installer/install.php' => APP_PATH.'/installer/install_'.rand(1,$rmax).'.php'),
        APP_PATH.'/install/install.php' => APP_PATH.'/install/install_'.rand(1,$rmax).'.php',
        APP_PATH.'/install/encode_pw_md5.php' => APP_PATH.'/install/encode_pw_md5_'.rand(1,$rmax).'.php',
        APP_PATH.'/install/initialize.php' => APP_PATH.'/install/initialize_'.rand(1,$rmax).'.php',
        APP_PATH.'/create_admin.php' => APP_PATH.'/create_admin_'.rand(1,$rmax).'.php',
    ));

$versions->add($version);
?>
